package com.study;

import com.study.netty2.NettyServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

import java.net.InetSocketAddress;

/**
 * @author mjy
 * @date 2021/12/07
 * @description
 */
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@EnableDiscoveryClient
@EnableFeignClients
public class NettyApplication2 implements CommandLineRunner {

    private final static Logger logger = LoggerFactory.getLogger(NettyApplication2.class);
    /**
     * 端口号
     */
    @Value("${netty.port}")
    private int port;

    /**
     * ip地址
     *
     * @param args
     * @throws Exception
     */
    @Value("${netty.url}")
    private String url;

    @Autowired
    private NettyServer server;

    /**
     * 项目启动后配置连接地址
     *
     * @param args
     * @throws Exception
     */
    @Override
    public void run(String... args) throws Exception {
        //配置netty连接地址
        InetSocketAddress address = new InetSocketAddress(url,port);
        logger.info("netty connect url={},port={}",url,port);
        server.start(address);
    }

    public static void main(String[] args) {
       SpringApplication.run(NettyApplication2.class,args);
    }
}
